package com.hpf.lease.web.admin.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hpf.lease.common.config.CommonException;
import com.hpf.lease.common.result.ResultCodeEnum;
import com.hpf.lease.model.bean.FeeValue;
import com.hpf.lease.web.admin.mapper.FeeValueMapper;
import com.hpf.lease.web.admin.service.FeeValueService;
import org.springframework.stereotype.Service;

/**
* @author GOD
* @description 针对表【fee_value(杂项费用值表)】的数据库操作Service实现
* @createDate 2024-08-29 15:00:50
*/
@Service
public class FeeValueServiceImpl extends ServiceImpl<FeeValueMapper, FeeValue>
    implements FeeValueService {

    @Override
    public boolean saveOrUpdateInfo(FeeValue feeValue) {
        Long id = feeValue.getId() == null ? -1L : feeValue.getId();
        FeeValue one = this.getOne(Wrappers.lambdaQuery(FeeValue.class)
                .eq(FeeValue::getName, feeValue.getName())
                .last("limit 1")
        );
        if (one != null && !feeValue.getId().equals(id)){
            throw new CommonException(ResultCodeEnum.FEE_VALUE_EXISTS_ERROR);
        }
        return this.saveOrUpdate(feeValue);
    }
}




